//app.js
const api = require("./utils/api.js");
const request = require("./service/request.js");
App({
  //当程序初始化的时候执行onLaunch里面的内容
  onLaunch: function () {

  },
  userLogin: function () {
    let that = this;
    let promise = new Promise((resolve, reject) => {
      wx.login({
        success: res => {
          wx.request({
            url: api.login,
            data: { 
              code: res.code,
              nickname: that.globalData.nickName,
              img: that.globalData.avatarUrl
            },
            method: "post",
            header: { 
              'Content-Type': 'application/x-www-form-urlencoded' 
            },
            success: res => {
              that.globalData.sessionid = res.data.sessionid
              resolve(res);
              console.log(res);
            },
            fail: err => {
              reject(err)
            }
          })
        }
      })
    })
    return promise;
  },
  

  //小程序显示的时候触发
  onShow:function(){
    console.log("生命周期函数-监听小程序显示的时候触发")
  },
  //小程序隐藏的时候触发
  onHide:function(){
    console.log("生命周期函数-监听小程序隐藏的时候触发")
  },
  //全局的属性
  globalData: {
    userInfo: null,
    nickName: "",
    avatarUrl: "",
    sessionid: "",
    isUpdate:false
  },

})